#ifndef FORGOTPASSWORDWIDGET_H
#define FORGOTPASSWORDWIDGET_H

#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QLabel>
#include <QProgressBar>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFormLayout>
#include <QGroupBox>
#include <QStackedWidget>
#include <QTimer>
#include <QCheckBox>
#include "authservice.h"

class ForgotPasswordWidget : public QWidget
{
    Q_OBJECT

public:
    explicit ForgotPasswordWidget(AuthService *authService, QWidget *parent = nullptr);
    virtual ~ForgotPasswordWidget();

signals:
    void switchToLogin();

private slots:
    void onSendResetEmailClicked();
    void onResetPasswordClicked();
    void onBackToLoginClicked();
    void onForgotPasswordSucceeded();
    void onForgotPasswordFailed(const QString &error);
    void onResetPasswordSucceeded();
    void onResetPasswordFailed(const QString &error);
    void onEmailChanged();
    void onTokenChanged();
    void onPasswordChanged();
    void onConfirmPasswordChanged();
    void onShowPasswordToggled(bool show);

private:
    void setupUI();
    void setupForgotCard(QWidget *centerCard);
    void setupEmailPage();
    void setupResetPage();
    void setUIEnabled(bool enabled);
    void clearForm();
    void applyStyles();
    bool validateEmail();
    bool validateResetForm();
    bool isValidEmail(const QString &email);
    bool isValidPassword(const QString &password);
    void switchToResetStep();
    void switchToEmailStep();

    AuthService *m_authService;

    // UI组件
    QVBoxLayout *m_mainLayout;
    QStackedWidget *m_stackedWidget;
    
    // 邮箱验证页面
    QWidget *m_emailPage;
    QGroupBox *m_emailGroup;
    QFormLayout *m_emailFormLayout;
    QLineEdit *m_emailEdit;
    QPushButton *m_sendEmailButton;
    QPushButton *m_backToLoginButton1;
    QLabel *m_emailHintLabel;
    QLabel *m_emailStatusLabel;
    QProgressBar *m_emailProgressBar;

    // 重置密码页面
    QWidget *m_resetPage;
    QGroupBox *m_resetGroup;
    QFormLayout *m_resetFormLayout;
    QLineEdit *m_tokenEdit;
    QLineEdit *m_newPasswordEdit;
    QLineEdit *m_confirmPasswordEdit;
    QCheckBox *m_showPasswordCheck;
    QPushButton *m_resetPasswordButton;
    QPushButton *m_backToLoginButton2;
    QLabel *m_tokenHintLabel;
    QLabel *m_passwordHintLabel;
    QLabel *m_confirmPasswordHintLabel;
    QLabel *m_resetStatusLabel;
    QProgressBar *m_resetProgressBar;

    // 通用组件
    QLabel *m_titleLabel;
    QLabel *m_logoLabel;
    QLabel *m_instructionLabel;

    // 样式
    QString m_primaryColor;
    QString m_secondaryColor;
    QString m_backgroundColor;
    QString m_textColor;
    QString m_errorColor;
    QString m_successColor;
    QString m_warningColor;
};

#endif // FORGOTPASSWORDWIDGET_H
